<?php

/**
 * 图文内容
 */

namespace Member\Logic;

class TextmsgLogic extends BaseLogic {
    
	protected $_auto = array(
	    array('uid',UID),
	);
	
	/**
	 * (non-PHPdoc)
	 * @see \Member\Logic\BaseLogic::update()
	 */
	public function update($id = 0){
		/* 获取文章数据 */
		$data = $this->create();
		
		$data['uid'] = UID;
		
		if($data === false){
			return false;
		}
		
		/* 添加或更新数据 */
		if(empty($data['id'])){//新增数据
			$data['id'] = $id;
			$id = $this->add($data);
			if(!$id){
				$this->error = '新增详细内容失败！';
				return false;
			}
		} else { //更新数据
			$status = $this->save($data);
			if(false === $status){
				$this->error = '更新详细内容失败！';
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see \Member\Logic\BaseLogic::autoSave()
	 */
	public function autoSave($id = 0){
		 
	}
	
	/**
	 * 添加消息
	 */
	public function saveData($text){
		
		$map = array(
				'uid'=>UID,
				'text'=>$text,
		);
		//查找之前是否存在该记录，如果存在，直接返回原来的id
		$textmsg = $this->where($map)->find();
		
		if($textmsg['id'] > 0){
		    return $textmsg['id'];
		}
		
	    $data = array(
	        'uid'=>UID,
	    	'createtime'=>time(),
	    	'text'=>$text,
	    );
	    return $this->add($data);
	}
}